#                                               -*- Autoconf -*-A
# Process this file with autoconf to produce a configure script.
AC_INIT(OpenDiameter, 1.0.7-j, gaeexp@gmail.com)
AM_INIT_AUTOMAKE([subdir-objects])

# Program Defaults
AC_ENABLE_SHARED

# Use of libtool
AC_PROG_LIBTOOL

# Checks for build environment 
# AC_CANONICAL_HOST

# Checks for environment
AC_MSG_CHECKING([existence of ACE_ROOT variable])
if test -z "$ACE_ROOT"; then 
   AC_MSG_RESULT(fail)
   AC_MSG_ERROR([ACE_ROOT not defined, you MUST install ACE or set ACE_ROOT if already installed]); 
else
   AC_MSG_RESULT(yes)
fi
AC_MSG_CHECKING([existence of BOOST_ROOT variable])
if test -z "$BOOST_ROOT"; then 
   AC_MSG_RESULT(fail)
   AC_MSG_ERROR([BOOST_ROOT not defined, you MUST install Boost or set BOOST_ROOT if already installed]); 
else
   AC_MSG_RESULT(yes)
fi
AC_MSG_CHECKING([existence of OPENSSL_ROOT variable])
if test -z "$OPENSSL_ROOT"; then 
   AC_MSG_RESULT(fail)
   AC_MSG_ERROR([OPENSSL_ROOT not defined, you MUST install OpenSSL or set OPENSSL_ROOT if already installed]); 
else
   AC_MSG_RESULT(yes)
fi
AC_MSG_CHECKING([existence of LKSCTP_ROOT variable])
if test -z "$LKSCTP_ROOT"; then 
   AC_MSG_RESULT(fail)
   AC_MSG_ERROR([LKSCTP_ROOT not defined, you MUST install lksctp-tools or set LKSCTP_ROOT if already installed]); 
else
   AC_MSG_RESULT(yes)
fi

# Checks for ODBC support
AC_ARG_ENABLE(odbc, AC_HELP_STRING([--enable-odbc], [Compiles Open Diameter Accounting with unixODBC support]))
if test "$enable_odbc" = "yes"; then
   AC_SUBST(L_ODBCFLAGS, ["-DAAA_ODBC_XFORMER"])
fi

# Checks for MPA support
AC_ARG_ENABLE(mpa, AC_HELP_STRING([--enable-mpa], [Compiles with MPA support]))
if test "$enable_mpa" = "yes"; then
   AC_SUBST(L_MPAFLAGS, ["-DPANA_MPA_SUPPORT"])
fi

# Checks for EAP-Archie inclusion 
AC_ARG_ENABLE(eap-archie, AC_HELP_STRING([--enable-eap-archie], [Compiles the EAP-Archie library]))
AM_CONDITIONAL([OPT_EAP_ARCHIE], [test "$enable_eap_archie" = "yes"]) 
if test "$enable_eap_archie" = "yes"; then
AC_MSG_CHECKING([existence of EAP_ARCHIE_ROOT variable])
if test -z "$EAP_ARCHIE_ROOT"; then 
   AC_MSG_RESULT(fail)
   AC_MSG_ERROR([EAP_ARCHIE_ROOT not defined, you MUST install eap-archie and make sure EAP_ARCHIE_ROOT points to the source tree]); 
else
   AC_MSG_RESULT(yes)
fi
fi

# Checks whether --with-eap-tls was given.
AC_ARG_WITH(eap-tls, [  --with-eap-tls          compile the EAP-TLS library])
AM_CONDITIONAL(compile_EAPTLS, [test "$with_eap_tls" = "yes"])

# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_LIBTOOL
AM_PROG_CC_C_O

# Checks for libraries.

# Checks for headers
AC_CHECK_HEADERS(ifaddrs.h)
AC_CHECK_HEADERS(net/if_dl.h)
AC_CHECK_HEADERS(shadow.h)

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE

# Checs for functions
AC_CHECK_FUNCS(getifaddrs)

# Substitutions
AC_SUBST(LIBTOOL_DEPS)
case $host in
  *-*-linux*)
     AC_SUBST(L_CPPFLAGS, ["-Wall -I$ACE_ROOT/include -I$BOOST_ROOT/include -I$OPENSSL_ROOT/include -I$LKSCTP_ROOT/include -fno-strict-aliasing"])
     AC_SUBST(L_CXXFLAGS, ["-Wall -I$ACE_ROOT/include -I$BOOST_ROOT/include -I$OPENSSL_ROOT/include -I$LKSCTP_ROOT/include -fno-strict-aliasing"])
     AC_SUBST(L_LDFLAGS, ["-L$ACE_ROOT/lib -L$BOOST_ROOT/lib -L$OPENSSL_ROOT/lib -L$LKSCTP_ROOT/lib"])
     AC_SUBST(L_LIBS, [" -lACE_SSL -lACEXML_Parser -lACEXML -lACE -lssl -lcrypto -lpthread -lsctp -ldl"])
     if test "$enable_shared" = "no"; then
        AC_SUBST(L_LIBS, [" -lACE_SSL -lACEXML_Parser -lACEXML -lACE -lssl -lcrypto -lpthread -lsctp -ldl $LIBS"])
     fi
     AC_SUBST(HOST_OS, [OS_LINUX])
  ;;
  *)
     AC_MSG_ERROR([Unsupported OS]); 
esac

# Standard libraries for distribution
AC_CONFIG_FILES([Makefile
                 libodutl/Makefile               
                 libdiameter/Makefile               
                 libdiamparser/Makefile
                 libeap/Makefile
                 libpana/Makefile
                 libdiametereap/Makefile
                 libdiametermip4/Makefile
                 libdiameternasreq/Makefile
                 libdiametercc/Makefile
                 libradius/Makefile
                 applications/Makefile
                 applications/nas/Makefile
                 applications/aaa/Makefile
                 applications/pana/Makefile])

# Generate output
AC_OUTPUT
